home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
asmutil
/
asm_n_z.zip
/
NOTEPAD4.ASM
< prev
next >
Wrap
Assembly Source File
|
1985-07-27
|
30KB
|
1,004 lines
PAGE 55,132
TITLE NOTEPAD4
;
;NotePad IV - NON BIOS VERSION
; Permission is granted to copy and distribute freely copies of this
; program with the following restrictions:
;
; 1) this program be passed in the public domain
; 2) a fee, beyond the cost of the disk, not be charged
; 3) improvements not be passed on but rather sent to me
; to check for possible incompatibilities with other programs
;
; (Stephen) Randy Davis and Larry Weiss
; (214)454-2426
;
; feel free to call with bugs or questions
;
;PARAMETERS -- MOST OF THESE MAY BE CHANGED TO ANY DESIRED VALUE
wndw_ht equ 24 ;mark the size of the window to open
wndw_wd equ 40
our_key equ 07100H ;scan code - ascii of key to open window
;now scan codes of edit keys (AltF10)
up_arrow equ 4800H
down_arrow equ 5000H
left_arrow equ 4B00H
right_arrow equ 4D00H
del_left equ 0008H ;user rubout (cntrl H) key
delete equ 5300H ;use del (lower right)
insert equ 5200H
cr equ 000DH
home equ 4700H
escape equ 001BH
tab equ 7400H ; ^right arrow
rev_tab equ 7300H ; ^left arrow
line_ins equ 5100H ;pg down
line_del equ 4900H ;pg up
mark_char equ 4F00H ;end key
print_char equ 372AH ;PrtSc* = print note on printer
file_change equ 4A2DH ;key to update file and get a new one
blank equ 07020H ;define the character which is a blank
attrib equ 070H ;and our default attribute (should agree with blank)
video equ 10H ;video BIOS call
inv_attrib equ 007H ;inverse of 'attrib'
PAGE
CSEG SEGMENT PARA PUBLIC 'CODE'
ASSUME CS:CSEG,DS:CSEG,SS:CSEG,ES:NOTHING ;STANDARD DECL FOR .COM FILE
ORG 100H
Start:
JMP INSTALL
;PLACE DATA AREA HERE FOR READIBILITY
COPYRITE DB 'Copyright Stephen R. Davis, Larry Weiss 1985 All Rights Reserved'
DB '(214)454-2426'
SCREENSAVE: DW (WNDW_HT * (WNDW_WD+1)) DUP (BLANK);RESERVE SPACE TO SAVE OPENED WINDOW
LINESAVE: DW WNDW_WD DUP (BLANK) ;BUFFER FOR LINE DELETE
CURSOR_POS DW 0
OLD_CUR_POS DW 0
SAVESTACK DW 0,0
REQUEST DB 0 ;REQUEST TYPE
KEY_RQST_HANDLER DD 0 ;ADDRESS OF THE ORIGINAL KEYBOARD REQUEST HANDLER
LEFT_MARG DB 00 ;define the confines of the window
RIGHT_MARG DB 00
TOP_MARG DB 00
BOT_MARG DB 00
UPPER_LEFT DW 00
MARK DW 00 ;FLAGS USED IN CHARACTER FEED
FEED_START DW 00 ;ADDRESS IN BUFFER OF BEGIN...
FEED_END DW 00 ;...AND END OF FEED
DISPLAY_SEG DW 00 ;DISPLAY SEGMENT (B000 -> MONOCHROME,
; B800 -> GRAPHIX)
FILE_NM_LOC DW 00 ;ADDRESS OF FILE NAME (0 -> NO FILE)
PAGE
BEGIN PROC FAR ;FAR LABEL SINCE ITS ENTERED BY INTERRUPT
MAINLOOP:
MOV CS:REQUEST,AH ;SAVE HIS AX REGISTER
MOV AX,CS:FEED_START ;ARE WE IN THE MIDDLE OF FEEDING CHARS...
CMP AX,CS:FEED_END ;...TO THE APPLICATION?
JZ NOFEED ;NO
JMP FEED ;YES
NOFEED:
MOV AH,CS:REQUEST ;RESTORE USERS AX
PUSHF ;CALL OLD INTERRUPT HANDLER (EMULATE INT INSTRUCTION)
CALL DWORD PTR [CS:KEY_RQST_HANDLER] ;GO AHEAD AND GET THE CHARACTER
PUSHF ;SAVE THE FLAG RETURNED (FOR AH = 1 REQUESTS)
CMP CS:REQUEST,00H ;WE ARE ONLY INTERESTED IN CHAR. REQUESTS
JZ CNTINUE
JMP FORGET_IT
CNTINUE: ;YES -- CHECK CHARACTER FOR 'OURS'
POPF ;FOR NON-TYPE 1 REQUESTS DONT NEED TO SAVE FLAGS
CMP AX,OUR_KEY
JZ CNT_AGIN
JMP RETURN_CHAR
CNT_AGIN: ;WE GOT IT! GO INTO EDITOR MODE
MOV CS:SAVESTACK,SP
MOV CS:SAVESTACK+2,SS
MOV AX,CS
MOV SS,AX
MOV SP,100H
STI ;ENABLE INTERRUPTS WHILE PROCESSING CHARACTERS
PUSH BP ;SET UP A STACK FRAME
MOV BP,SP
SUB SP,0EH
CALL SAVEREG
MOV DS,AX
CALL CALC_WINDOW ;CALCULATE WINDOW EXTREMETIES
CALL READ_CURSOR
MOV OLD_CUR_POS,DX ;SAVE THE CURSOR FOR LATER RESTORING
CALL WINDOW_SWAP ;SWING IN THE EDIT WINDOW (WITH NOTES?)
CALL INSERT_CR ;PUT THE CARRIAGE RETURNS ON UNPRINTABLE COL.S
MOV DX,CURSOR_POS ;RESTORE CURSOR IN EDIT WINDOW
CALL PLACE_CURSOR
CALL EDITOR ;LET HIM EDIT IN THE WINDOW
CALL READ_CURSOR
MOV CURSOR_POS,DX ;SAVE CURSOR IN EDIT WINDOW FOR NEXT EDIT
CMP MARK,00H ;CLEAR THE MARK POSITION (IF IT'S SET)
JZ NOT_SET
MOV DX,MARK
CALL READ_CHAR ;GET THE CHARACTER...
MOV AH,ATTRIB ;...PUT ITS ATTRIBUTE BACK TO EVERYONE ELSE'S...
CALL WRITE_CHAR ;...AND PUT IT BACK
MOV MARK,00H
NOT_SET:
CALL WINDOW_SWAP ;PUT BACK WHATEVER WAS ORIGINALLY THERE
CALL UPDATE_FILE ;NOW ATTEMPT TO UPDATE THE DISK FILE
MOV DX,OLD_CUR_POS ;RESTORE THE CURSOR POSITION
CALL PLACE_CURSOR
CALL RESTREG
ADD SP,0EH
POP BP
MOV SS,CS:SAVESTACK+2
MOV SP,CS:SAVESTACK
MOV AH,00 ;RESTORE REQUEST TO SOMETHING DECENT
JMP MAINLOOP ;GO GET ANOTHER CHARACTER TO RETURN HIM
RETURN_CHAR:
IRET ;RETURN WITH CHARACTER
;HANDLE REQUEST TYPE 1'S BY FAR RETURNING 2 AND TYPE 2'S BY JUST RETURNING
FORGET_IT:
CMP CS:REQUEST,1 ;was it a "is char present" request?
JZ FI100
POPF ;no -- just return whatever BIOS returned
IRET
FI100:
POPF ;yes -- make funny return
RET 02
PAGE
;HERE WE ARE IN THE PROCESS OF FEEDING CHARACTERS TO THE APPLICATION
;FROM THE WINDOW BUFFER (SCREENSAVE)
FEED:
CMP CS:REQUEST,1 ;WAS THIS A CHAR TYPE REQUEST?
JA KSTAT
;YES -- RETURN HIM CHAR
PUSH BX ;GET THE NEXT CHARACTER FROM THE BUFFER
CALL SKIP_SPACES ;STRIP LEADING SPACES
MOV BX,CS:FEED_START ;OK - GET THE NEXT CHARACTER WE NEED
MOV AX,CS:[BX]
POP BX
XOR AH,AH ;WE NO LONGER HAVE THE SCAN CODE, BUT ALL
;ARE ASCII ANYWAY
CMP CS:REQUEST,0 ;IS THIS A 'GET KEYBOARD CHAR' RQST?
JNZ FEED_KEY_STAT
ADD CS:FEED_START,2 ;YES -- MOVE UP THE POINTER BY 1
IRET
FEED_KEY_STAT:
STI ;NO -- ENABLE INTERRUPTS AND FEED HIM THE
RET 02 ;THE Z FLAG CLEAR WITH HIS CHAR
KSTAT:
MOV AH,CS:REQUEST ;RESTORE REQUEST TO AH
CALL DWORD PTR [CS:KEY_RQST_HANDLER] ;PERFORM BIOS CALL -- WE DON'T KNOW
;WHAT HE'S DOING AND WE SHOULDN'T GET IN THE WAY
IRET ;RETURN THE RESULTS TO HIM (WHATEVER THEY ARE)
BEGIN ENDP
PAGE
BODY PROC NEAR ;MAKE SHORT CALLS ONLY TO THE MAIN ROUTINES
SKIP_SPACES:
;TRY TO AVOID FEEDING SPACES WITH NOTHING AFTER THEM ON A LINE --
;JUST SKIP OVER TO THE RETURN AND FEED THAT ALONE
MOV BX,CS:FEED_START ;START WITH THE NEXT FEED CHARACTER
LOOK_AHEAD:
MOV AX,CS:[BX]
CMP AL,CR ;IS THIS CHAR A RETURN
JZ STRIP_SPACES
CMP AL,' ' ;IS THIS CHARACTER ANOTHER SPACE?
JNZ GO_ON
ADD BX,2 ;YES -- KEEP LOOKING AHEAD
CMP BX,CS:FEED_END ;IS THAT IT?
JNZ LOOK_AHEAD
;YES--
SUB BX,2 ;RAN OFF THE END -- BACK UP ONE CHAR AT LEAST!
STRIP_SPACES:
MOV CS:FEED_START,BX ;HERE WE FOUND NOTHING BUT SPACES BEFORE THE
;CARRIAGE RETURN -- SKIP THA